package com.tjh.spring5.service;

import com.tjh.spring5.dao.TransactionalUserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * day33：
 *      声明式事务管理（注解方式） + 事务参数
 */
@Service
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.REPEATABLE_READ,timeout = -1,readOnly = false)
public class UserService_day33 {

    //注入dao
    @Autowired
    private TransactionalUserDao userDao;

    //转账的方法
    public void accountMoney() {
        //lucy少100
        userDao.reduceMoney();

        //模拟异常
        int i = 10 / 0;

        //mary多100
        userDao.addMoney();
    }
}
